program q1035;
var
    i, j, sidx, didx, total, delta, cntp, n:longint;
    p, target:string;
    name: array[1..10] of string;
    get: array[1..10] of longint;
begin
    assign(input, '');
    assign(output, '');
    reset(input);
    rewrite(output);

    readln(n);
    for i:=1 to n do begin
        readln(name[i]);
        get[i] := 0;
    end;

    while not eof(input) do begin
        readln(p);
        for i:=1 to n do begin
            if (p = name[i]) then begin
                sidx := i;
                break;
            end;
        end;

        readln(total, cntp);
        get[sidx] := get[sidx] - total;
        if (cntp <> 0) then begin
            delta := total div cntp;
            get[sidx] := get[sidx] + (total mod cntp);
        end
        else delta := 0;

        for i:=1 to cntp do begin
            readln(target);
            for j:=1 to n do begin
                if (target = name[j]) then begin
                    didx := j;
                    break;
                end;
            end;
            get[didx] := get[didx] + delta;
        end;
    end;

    for i:=1 to n do
        writeln(name[i], ' ', get[i]);
 
    close(input);
    close(output);
end.
